home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / AMIGA / gramiga.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  10KB  |  418 lines

  1. /* --------------------------------- grAmiga.c ---------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* graphics driver for the Amiga: By Michael Taylor
  8. */
  9.  
  10. #include "fly.h"
  11.  
  12. #include "amigainc.h"
  13.  
  14.  
  15. extern struct IntuitionBase *IntuitionBase;
  16. #ifdef _DCC
  17. extern struct GfxBase *GfxBase;
  18. #else
  19. struct GfxBase *GfxBase = NULL;
  20. #endif
  21.  
  22. #define INTUITION_REV    33L
  23. #define DEPTH        3  
  24. #define WIDTH        (dev->sizex)
  25. #define HEIGHT        (dev->sizey)
  26.  
  27. #define YOFFSET        0
  28. #define XOFFSET        0
  29.  
  30. static int height, width;
  31.  
  32. static struct Screen *screen1 = NULL;
  33. static struct NewScreen Fly8Screen = {
  34.     0,                /* the LeftEdge must be zero */
  35.     0,                /* TopEdge */
  36.     640,              /* Width (high-resolution) */
  37.     400,            /* Height (NTSC interlace)  */
  38.     DEPTH,            /* Depth 2^DEPTH = number of colours */
  39.     1, 0,             /* DetailPen and BlockPen specifications */
  40.     HIRES,            /* the high-resolution display mode */
  41.     CUSTOMSCREEN,     /* the screen type */
  42.     NULL,             /* no special font */
  43.     "Fly8  by  Eyal Lebedinsky", /* the screen title */
  44.     NULL,             /* no special screen gadgets */
  45.     NULL              /* no CustomBitMap */
  46. };
  47.  
  48. struct Window *window1 = NULL;
  49. static struct NewWindow Fly8Window = {
  50.     0,
  51.     YOFFSET,
  52.     320,
  53.     200,
  54.     0,1,         /* Plain vanilla DetailPen and BlockPen.       */
  55.     CLOSEWINDOW, /* Tell program when close gadget has been hit */
  56.     WINDOWCLOSE | SMART_REFRESH | ACTIVATE | WINDOWDRAG | BORDERLESS |
  57.     WINDOWDEPTH | WINDOWSIZING | NOCAREREFRESH | RAWKEY,
  58.     NULL,             /* Pointer to the first gadget -- */
  59.                       /*   may be initialized later.    */
  60.     NULL,             /* No checkmark.   */
  61.     NULL,          /* Window title.   */
  62.     NULL,             /* Attach a screen later.  */
  63.     NULL,             /* No bitmap.          */
  64.     100,          /* Minimum width.      */
  65.     25,          /* Minimum height.     */
  66.     0xFFFF,           /* Maximum width.      */
  67.     0xFFFF,           /* Maximum height.     */
  68.     CUSTOMSCREEN      /* A screen of our own. */
  69. };
  70.  
  71. #define WHITE          0xfff
  72. #define BRICKRED     0xd00
  73. #define RED            0xf00
  74. #define REDORANGE     0xf80
  75. #define ORANGE         0xf90
  76. #define GOLDENORANGE    0xfb0
  77. #define YELLOW         0xfd0
  78. #define LEMONYELLOW    0xff0
  79. #define LIMEGREEN    0xbf0
  80. #define LIGHTGREEN    0x8e0
  81. #define GREEN          0x0f0
  82. #define DARKGREEN    0x2c0
  83. #define FORESTGREEN    0x0b1
  84. #define BLUEGREEN    0x0bb
  85. #define AQUA           0x0db
  86. #define LIGHTAQUA    0x1fb
  87. #define SKYBLUE        0x6fe
  88. #define LIGHTBLUE    0x6ce
  89. #define BLUE           0x00f
  90. #define BRIGHTBLUE    0x51f
  91. #define DARKBLUE    0x06d
  92. #define PURPLE         0x91f
  93. #define VIOLET         0xc1f
  94. #define MAGENTA        0xf1f
  95. #define PINK           0xfac
  96. #define TAN            0xdb9
  97. #define BROWN          0xc80
  98. #define DARKBROWN     0xa87
  99. #define LIGHTGREY       0xccc
  100. #define GRAY           0x999
  101. #define BLACK          0x000
  102.  
  103. #define COLOR0 0
  104. #define COLOR1 1
  105. #define COLOR2 2
  106. #define COLOR3 3
  107.  
  108. static int cleanExit(int exitStatus);
  109.  
  110. static void 
  111. GrMoveTo (int x, int y)
  112. {
  113.     Move (window1->RPort, x, y+YOFFSET);
  114. }
  115.  
  116. static void 
  117. GrDrawTo (int x, int y, Uint color)
  118. {
  119.     SetAPen(window1->RPort, (UBYTE)color);
  120.     Draw (window1->RPort, x, y+YOFFSET);
  121. }
  122.  
  123. static int FAR
  124. GrWriteMode (int mode)
  125. {
  126. #if 0
  127.     switch (mode) {
  128.     default:
  129.     case T_MSET:
  130.         mode = GXcopy;
  131.         break;
  132.     case T_MOR:
  133.         mode = GXor;
  134.         break;
  135.     case T_MXOR:
  136.         mode = GXxor;
  137.         break;
  138.     }
  139.     XSetFunction (TheDisplay, TheGC, mode);
  140. #endif
  141.     return (0);
  142. }
  143.  
  144. static int
  145. SetPalette (int n, long c)
  146. {
  147.     int    r, g, b;
  148.  
  149.     r = 0x0ff & ((int)(c      )); 
  150.     g = 0x0ff & ((int)(c >>  8)); 
  151.     b = 0x0ff & ((int)(c >> 16));
  152.     SetRGB4(&screen1->ViewPort, (SHORT)n,
  153.         (UBYTE)(r >> 4), (UBYTE)(g >> 4), (UBYTE)(b >> 4));
  154.     return (0);
  155. }
  156.  
  157. static int 
  158. GrInit (DEVICE *dev)
  159. {
  160.     static UWORD colortable[] =
  161.     {
  162.         BLACK, WHITE, RED, GREEN, BLUE, BROWN, MAGENTA, GRAY, YELLOW,
  163.         LEMONYELLOW, LIGHTBLUE, REDORANGE, BRICKRED, ORANGE, 
  164.         GOLDENORANGE, LIMEGREEN, LIGHTGREEN, DARKGREEN, FORESTGREEN, 
  165.         BLUEGREEN, AQUA, LIGHTAQUA, SKYBLUE, BRIGHTBLUE, DARKBLUE,
  166.         PURPLE, VIOLET, PINK, TAN, DARKBROWN, LIGHTGREY, WHITE
  167.     };
  168.  
  169.  
  170. #ifndef _DCC
  171.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 33L);
  172.     if (GfxBase == NULL) {
  173.         printf("Error: Cannot open Graphics library\n");
  174.         return cleanExit(ERROR_INVALID_RESIDENT_LIBRARY);
  175.     }
  176. #endif
  177.     height = HEIGHT;
  178.         Fly8Screen.Width = WIDTH;
  179.         Fly8Screen.Height = HEIGHT;
  180.         if (dev->colors == 32)
  181.         Fly8Screen.Depth = 5;
  182.         else if (dev->colors == 16)
  183.         Fly8Screen.Depth = 4;
  184.         else if (dev->colors == 8)
  185.         Fly8Screen.Depth = 3;
  186.         else if (dev->colors == 4)
  187.         Fly8Screen.Depth = 2;
  188.         else if (dev->colors == 2)
  189.         Fly8Screen.Depth = 1;
  190.     if (WIDTH == 320)
  191.             Fly8Screen.ViewModes = 0;
  192.         else if (HEIGHT + YOFFSET >= 400)
  193.             Fly8Screen.ViewModes = HIRES | LACE;
  194.         else
  195.             Fly8Screen.ViewModes = HIRES;
  196.  
  197.         /* Open the screen */
  198.         screen1 = OpenScreen(&Fly8Screen);
  199.         if (screen1 == NULL) {
  200.             printf ("Error: could not create screen\n");
  201.         return cleanExit(RETURN_WARN);
  202.     }
  203.         
  204.     /* Initialize the screen ViewPort's ColorMap. */
  205.     screen1->ViewPort.ColorMap = GetColorMap(32L);
  206.     if (screen1->ViewPort.ColorMap == NULL) {
  207.             printf ("Error: could not create screen\n");
  208.             return cleanExit(ERROR_NO_FREE_STORE);
  209.     }
  210.     LoadRGB4(&screen1->ViewPort, (UWORD *)colortable, (WORD)32);
  211.  
  212.     /* initialize the new windows attributes */
  213.     Fly8Window.LeftEdge  = 0;
  214.     Fly8Window.TopEdge   = 0;
  215.     Fly8Window.Width     = dev->sizex; /*WIDTH*/
  216.     Fly8Window.Height    = HEIGHT + YOFFSET;
  217.     Fly8Window.MinWidth  = Fly8Window.Width;
  218.     Fly8Window.MinHeight = Fly8Window.Height;
  219.     Fly8Window.Title     = (unsigned char *)"Fly8";
  220.         Fly8Window.Screen    = screen1;
  221.     Fly8Window.DetailPen = 0;
  222.     Fly8Window.BlockPen  = 1;
  223.     Fly8Window.Title = NULL;
  224.     Fly8Window.Flags = BORDERLESS | SMART_REFRESH | NOCAREREFRESH | RMBTRAP;
  225.     Fly8Window.IDCMPFlags = MOUSEMOVE | MOUSEBUTTONS | RAWKEY;
  226.         /* Open the window */
  227.  
  228.         window1 = OpenWindow(&Fly8Window);
  229.         if (window1 == NULL) {
  230.             printf ("Error: could not create graphics window 1\n");
  231.         return cleanExit(RETURN_WARN);
  232.     }
  233.  
  234.     black   = 0;    /* cannot change */
  235.     white   = 1;    /* cannot change */
  236.     if (dev->colors < 16) {
  237.         red = blue = magenta = green = white;
  238.         brown = gray = hudlow = hudhigh = white;
  239.         lblue = lred = white;
  240.         SetPalette (black,   C_BLACK);
  241.         SetPalette (white,   C_WHITE);
  242.     } else {    
  243.         red     = 2;    /* do not change! */
  244.         blue    = 4;    /* do not change! */
  245.         magenta = 6;    /* do not change! */
  246.         green   = 3;
  247.         brown   = 5;
  248.         gray    = 7;
  249.         hudlow  = 8;
  250.         hudhigh = 9;
  251.         lblue   = 10;
  252.         lred    = 11;
  253. /*        white   = 15;    keep 15 for OR'ed white */
  254.         SetPalette (black,   C_BLACK);
  255.         SetPalette (white,   C_WHITE);
  256.         SetPalette (red,     C_RED);
  257.         SetPalette (blue,    C_BLUE);
  258.         SetPalette (magenta, C_MAGENTA);
  259.         SetPalette (green,   C_GREEN);
  260.         SetPalette (brown,   C_BROWN);
  261.         SetPalette (gray,    C_GRAY);
  262.         SetPalette (hudlow,  C_LYELLOW);
  263.         SetPalette (hudhigh, C_YELLOW);
  264.         SetPalette (lred,    C_LIGHTRED);
  265.         SetPalette (lblue,   C_SKYBLUE);
  266.     }
  267.     
  268.     /* Simple form of setting drawing area to BLACK */
  269.     SetRast(window1->RPort, black);
  270.  
  271.     ActivateWindow (window1);
  272.     RefreshWindowFrame (window1);
  273.  
  274.     dev->npages = 1;
  275.     return (0);
  276. }
  277.  
  278. static void
  279. GrTerm (DEVICE *dev)
  280. {
  281.     cleanExit (0);
  282. }
  283.  
  284. static int 
  285. cleanExit(int exitStatus)
  286. {
  287.     short i;
  288.  
  289.         if (window1)
  290.         CloseWindow( window1 );
  291.  
  292. /* Free the color map created by GetColorMap(). */
  293.     if (screen1->ViewPort.ColorMap)
  294.         FreeColorMap(screen1->ViewPort.ColorMap);
  295.  
  296.     if (screen1)
  297.         CloseScreen( screen1 );
  298.         
  299. #ifndef _DCC
  300.     if (GfxBase)
  301.         CloseLibrary((struct Library *)GfxBase);
  302. #endif
  303.     if (exitStatus)
  304.         return (exitStatus);
  305. }
  306.  
  307. static int
  308. GrSetActive (int page)
  309. {return (0);}
  310.  
  311. static int
  312. GrSetVisual (int page)
  313. {return (0);}
  314.  
  315. static void FAR
  316. Ellipse (register int x1, register int y1, int rx, int ry, register Uint color)
  317. {
  318.     int    ax, bx, cx, dx, ay, by, cy, dy;
  319.  
  320.     ax = fmul ( 3196, rx);        /* sin (pi/16) */
  321.     ay = fmul ( 3196, ry);
  322.     bx = fmul ( 9102, rx);        /* sin (3*pi/16) */
  323.     by = fmul ( 9102, ry);
  324.     cx = fmul (13623, rx);        /* sin (5*pi/16) */
  325.     cy = fmul (13623, ry);
  326.     dx = fmul (16069, rx);        /* sin (7*pi/16) */
  327.     dy = fmul (16069, ry);
  328.  
  329.     GrMoveTo (x1+dx, y1-ay);
  330.     GrDrawTo (x1+cx, y1-by, color);
  331.     GrDrawTo (x1+bx, y1-cy, color);
  332.     GrDrawTo (x1+ax, y1-dy, color);
  333.     GrDrawTo (x1-ax, y1-dy, color);
  334.     GrDrawTo (x1-bx, y1-cy, color);
  335.     GrDrawTo (x1-cx, y1-by, color);
  336.     GrDrawTo (x1-dx, y1-ay, color);
  337.     GrDrawTo (x1-dx, y1+ay, color);
  338.     GrDrawTo (x1-cx, y1+by, color);
  339.     GrDrawTo (x1-bx, y1+cy, color);
  340.     GrDrawTo (x1-ax, y1+dy, color);
  341.     GrDrawTo (x1+ax, y1+dy, color);
  342.     GrDrawTo (x1+bx, y1+cy, color);
  343.     GrDrawTo (x1+cx, y1+by, color);
  344.     GrDrawTo (x1+dx, y1+ay, color);
  345.     GrDrawTo (x1+dx, y1-ay, color);
  346. }
  347.  
  348. static void
  349. Sync (void)
  350. {}
  351.  
  352. static void
  353. Flush (void)
  354. {}
  355.  
  356. static void
  357. GrShutters (int eye)
  358. {}
  359.  
  360. struct GrDriver GrAmiga = {
  361.     "GrAmiga",
  362.     0,
  363.     0,
  364.     GrInit,
  365.     GrTerm,
  366.     GrMoveTo,
  367.     GrDrawTo,
  368.     GrSetVisual,
  369.     GrSetActive,
  370.     0,
  371.     GrWriteMode,
  372.     SetPalette,
  373.     Ellipse,
  374.     Flush,
  375.     GrShutters
  376. };
  377. #undef INTUITION_REV
  378. #undef DEPTH
  379. #undef WIDTH
  380. #undef HEIGHT
  381. #undef YOFFSET
  382. #undef XOFFSET
  383. #undef WHITE
  384. #undef BRICKRED
  385. #undef RED
  386. #undef REDORANGE
  387. #undef ORANGE
  388. #undef GOLDENORANGE
  389. #undef YELLOW
  390. #undef LEMONYELLOW
  391. #undef LIMEGREEN
  392. #undef LIGHTGREEN
  393. #undef GREEN
  394. #undef DARKGREEN
  395. #undef FORESTGREEN
  396. #undef BLUEGREEN
  397. #undef AQUA
  398. #undef LIGHTAQUA
  399. #undef SKYBLUE
  400. #undef LIGHTBLUE
  401. #undef BLUE
  402. #undef BRIGHTBLUE
  403. #undef DARKBLUE
  404. #undef PURPLE
  405. #undef VIOLET
  406. #undef MAGENTA
  407. #undef PINK
  408. #undef TAN
  409. #undef BROWN
  410. #undef DARKBROWN
  411. #undef LIGHTGREY
  412. #undef GRAY
  413. #undef BLACK
  414. #undef COLOR0
  415. #undef COLOR1
  416. #undef COLOR2
  417. #undef COLOR3
  418.